#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <assert.h>
#include "include/vector.h"
#include "include/queue.h"
#include "include/loop_queue.h"

// 测试循环队列和数组队列的性能差异
double testQueue(void (*enqueue)(void*, int), int (*dequeue)(void*),
        void* queue, int opCount) {
    time_t start = time(NULL);
    for (int i = 0; i < opCount; i++)
        enqueue(queue, i);
    for (int i = 0; i < opCount; i++)
        dequeue(queue);
    time_t end = time(NULL); 
    // printf("Time taken: %f seconds\n", difftime(end, start));
    return difftime(end, start); 
}

// Queue opCount = 100000, cost time 11.000000000
// LoopQueue opCount = 100000, cost time 0.000000000
int main(int argc, const char* argv[]) {
    int opCount = 100000; //10万次
    Queue q;
    LoopQueue lq;
    QueueNew(&q);
    LoopQueueNew(&lq);
    double t1 = testQueue(QueueEnqueue, QueueDequeue, &q, opCount);
    printf("Queue opCount = %d, cost time %.9f\n", opCount, t1);
    double t2 = testQueue(LoopQueueEnqueue, LoopQueueDequeue, &lq, opCount);
    printf("LoopQueue opCount = %d, cost time %.9f\n", opCount, t2);
    QueueDispose(&q);
    LoopQueueDispose(&lq);
    return 0;
}